package com.bilin.coin.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bilin.coin.ApiConstant;
import com.bilin.coin.R;
import com.bilin.coin.bean.CommonSuccessEvent;
import com.bilin.coin.bean.UserInfo;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.utils.GsonUtil;
import com.bilin.coin.utils.SharedPreferencesUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.OnClick;




@Route(path = "/safe/AuthFailureActivity")
public class AuthFailureActivity extends BaseAppCompatActivity {

    @BindView(R.id.tv_reason)
    TextView tv_reason;

    @Override
    protected void initView() {
        setTitle("身份认证失败");
        String json = SharedPreferencesUtils.getInstance().getString(ApiConstant.USERINFO_JSON, "");
        if (TextUtils.isEmpty(json)) {
            getSession();
        } else {
            UserInfo userInfo = GsonUtil.GsonToBean(json, UserInfo.class);
            String kycCancelReason = userInfo.getKycCancelReason();
            if (TextUtils.isEmpty(kycCancelReason)) {
                getSession();
            } else {
                tv_reason.setText(kycCancelReason);
            }
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_auth_failure;
    }

    @OnClick({R.id.bt_confirm})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_confirm:
                lowAuth();
                break;
        }
    }

    private void lowAuth() {
        baseStartActivity("/v2/safe/AuthActivity");
    }

    @Override
    public void userInfoSession(UserInfo sessionBean) {
        tv_reason.setText(sessionBean.getKycCancelReason());
    }

    /**
     * 认证成功
     *
     * @param addressOpSuccessEvent
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void authSuccessEvent(CommonSuccessEvent addressOpSuccessEvent) {
        if (addressOpSuccessEvent.getType() == CommonSuccessEvent.AuthSuccess) {
            finish();
        }
        EventBus.getDefault().removeStickyEvent(addressOpSuccessEvent);
    }
}
